package jw.guli.eduservice.controller;


import com.alibaba.excel.util.StringUtils;
import jw.guli.commonutils.R;
import jw.guli.eduservice.client.VodClient;
import jw.guli.eduservice.entity.EduVideo;
import jw.guli.eduservice.service.EduVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author jiangw
 * @since 2021-01-30
 */
@RestController
@RequestMapping("/eduservice/edu-video")
//@CrossOrigin
public class EduVideoController {
    @Autowired
    private EduVideoService videoService;
    @Autowired
    VodClient vodClient;
    //添加小节
    @PostMapping("addVideo")
    public R addVideo(@RequestBody EduVideo eduVideo) {
        videoService.save(eduVideo);
        return R.ok();
    }

    //删除小节
    @DeleteMapping("{id}")
    public R deleteVideo(@PathVariable String id) {
        EduVideo eduVideo = videoService.getById(id);
        String videoSourceId = eduVideo.getVideoSourceId();
        if(!StringUtils.isEmpty(videoSourceId)){

            vodClient.removeAliyunVideo(videoSourceId);
        }
        videoService.removeById(id);
        return R.ok();
    }

}

